package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.NoticeFunctionBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/6.
 */
public class RemindApater extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private List<NoticeFunctionBean> datas;
    private RecyclerView recyclerview;
    private LayoutInflater mInflater;

    private ResultSelectedListener listener;

    public RemindApater(Context mContext, List<NoticeFunctionBean> datas, RecyclerView recyclerview) {
        this.mContext = mContext;
        this.datas = datas;
        this.recyclerview = recyclerview;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setResultListener(ResultSelectedListener listener) {
        this.listener = listener;
    }

    public void setData(List<NoticeFunctionBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // TODO Auto-generated method stub
        return datas.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        // TODO Auto-generated method stub


        Holder mHolder = (Holder) holder;
        mHolder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSelected("layout", position);
            }
        });
//        if (position == 0) {
//            mHolder.statusIV.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.remind_past));
//            mHolder.discriptionTV.setText("请您携带检查结果，按预约时间及时复查");
//        } else if (position == 1) {
//            mHolder.statusIV.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.remind_article));
//            mHolder.discriptionTV.setText(Html.fromHtml("<u>" + "康复训练文章视频" + "</u>"));
//
//            mHolder.discriptionTV.setTextColor(mContext.getResources().getColor(R.color.light_blue));
//        } else if (position == 2) {
//            mHolder.statusIV.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.remind_editor));
//            mHolder.discriptionTV.setText(Html.fromHtml("<u>" + "测量血压--点击录入" + "</u>"));
//            mHolder.discriptionTV.setTextColor(mContext.getResources().getColor(R.color.light_blue));
//        }

        NoticeFunctionBean bean = datas.get(position);
        if (bean.getType().equals("0")) {//0是测量1是文章2是文字
            mHolder.statusIV.setImageResource(R.mipmap.remind_editor);
            mHolder.discriptionTV.setTextColor(ContextCompat.getColor(mContext, R.color.light_blue));
            mHolder.discriptionTV.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        } else if (bean.getType().equals("1")) {
            mHolder.statusIV.setImageResource(R.mipmap.remind_article);
            mHolder.discriptionTV.setTextColor(ContextCompat.getColor(mContext, R.color.light_blue));
            mHolder.discriptionTV.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        } else {
            mHolder.statusIV.setImageResource(R.mipmap.remind_past);
            mHolder.discriptionTV.setTextColor(ContextCompat.getColor(mContext, R.color.black_text));
        }
        if (bean.getType().equals("0")) {
            mHolder.discriptionTV.setText(bean.getContent() + "--点击录入");
        } else {
            mHolder.discriptionTV.setText(bean.getContent());
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View v = mInflater.inflate(R.layout.item_layout_remind, null);
        RecyclerView.ViewHolder holer = new Holder(v);

        return holer;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    /*
     * Holder
     */
    public class Holder extends RecyclerView.ViewHolder {

        private LinearLayout layout;

        private ImageView statusIV;

        private TextView discriptionTV;


        public Holder(View view) {
            super(view);

            layout = (LinearLayout) view.findViewById(R.id.remindlist_item_layout_remind);
            statusIV = (ImageView) view.findViewById(R.id.remindlist_item_iv_status);
            discriptionTV = (TextView) view.findViewById(R.id.remindlist_item_tv_descprtion);


        }
    }

    public interface ResultSelectedListener {
        void onSelected(String type, int position);
    }

}
